<?php


namespace app\model\hotel;

use think\facade\Cache;
use app\model\BaseModel;

/**
 * 酒店标签
 */
class HotelLabel extends BaseModel
{

    /**
     * 添加酒店标签
     *
     * @param array $data
     */
    public function addHotelLabel($data)
    {

        $res = model('hotel_label')->add($data);
        Cache::tag("hotel_label")->clear();
        return $this->success($res);
    }

    /**
     * 修改酒店标签
     *
     * @param array $data
     * @param array $condition
     */
    public function editHotelLabel($data, $condition)
    {

        $res = model('hotel_label')->update($data, $condition);
        Cache::tag("hotel_label")->clear();
        return $this->success($res);
    }

    /**
     * 删除酒店标签
     * @param array $condition
     */
    public function deleteHotelLabel($condition)
    {
        $res = model('hotel_label')->delete($condition);
        Cache::tag("hotel_label")->clear();
        return $this->success($res);
    }

    /**
     * 修改标签排序
     * @param int $sort
     * @param int $label_id
     */
    public function modifyHotelLabelSort($sort, $label_id)
    {
        $res = model('hotel_label')->update([ 'sort' => $sort ], [ [ 'label_id', '=', $label_id ] ]);
        Cache::tag("hotel_label")->clear();
        return $this->success($res);
    }

    /**
     * 获取酒店标签信息
     *
     * @param array $condition
     * @param string $field
     */
    public function getHotelLabelInfo($condition = [], $field = '*')
    {

        $data = json_encode([ $condition, $field ]);
        $cache = Cache::get("hotel_label_getHotelLabelInfo_" . $data);
        if (!empty($cache)) {
            return $this->success($cache);
        }
        $info = model('hotel_label')->getInfo($condition, $field);
        Cache::tag("hotel_label")->set("hotel_label_getHotelLabelInfo_" . $data, $info);
        return $this->success($info);
    }

    /**
     * 获取酒店标签列表
     *
     * @param array $condition
     * @param string $field
     * @param string $order
     * @param string $limit
     */
    public function getHotelLabelList($condition = [], $field = '*', $order = 'sort asc, label_id asc', $limit = null)
    {

        $data = json_encode([ $condition, $field, $order, $limit ]);
        $cache = Cache::get("hotel_label_getHotelLabelList_" . $data);

        if (!empty($cache)) {
            return $this->success($cache);
        }

        $list = model('hotel_label')->getList($condition, $field, $order, '', '', '', $limit);
        Cache::tag("hotel_label")->set("hotel_label_getHotelLabelList_" . $data, $list);

        return $this->success($list);
    }

    /**
     * 获取酒店标签分页列表
     *
     * @param array $condition
     * @param number $page
     * @param string $page_size
     * @param string $order
     * @param string $field
     */
    public function getHotelLabelPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'sort asc, level_id asc', $field = '*')
    {

        $data = json_encode([ $condition, $field, $order, $page, $page_size ]);
        $cache = Cache::get("hotel_label_getHotelLabelPageList_" . $data);
        if (!empty($cache)) {
            return $this->success($cache);
        }
        $list = model('hotel_label')->pageList($condition, $field, $order, $page, $page_size);
        Cache::tag("hotel_label")->set("hotel_label_getHotelLabelPageList_" . $data, $list);
        return $this->success($list);
    }
}